package com.kabigon.tiny.convert;

import com.kabigon.tiny.dto.MemberDto;
import com.kabigon.tiny.dto.MemberOrderDto;
import com.kabigon.tiny.po.Member;
import com.kabigon.tiny.po.Order;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import org.springframework.core.convert.converter.Converter;

/**
 * 会员对象映射
 * @author xu.biao
 * @version v1.0
 * @Package com.kabigon.tiny.convert
 * @data 2022/5/27 0:59
 */
@Mapper
public interface MemberConvert extends Converter<Member, MemberDto> {

    MemberConvert INSTANCE = Mappers.getMapper(MemberConvert.class);

    @Mapping(source = "phone", target = "phoneNumber")
    @Mapping(source = "birthday", target = "birthday", dateFormat = "yyyy-MM-dd")
    MemberDto toDto(Member member);

    //@Mapping(target = "phoneNumber", source = "phone")
    //@Mapping(target = "birthday", source = "birthday", dateFormat = "yyyy-MM-dd")
    //List<MemberDto> toDtoList(List<Member> list);

    @Mapping(target = "phoneNumber", source = "member.phone")
    @Mapping(target = "birthday", source = "member.birthday", dateFormat = "yyyy-MM-dd")
    @Mapping(target = "orderSn", source = "order.orderSn")
    @Mapping(target = "receiverAddress", source = "order.receiverAddress")
    @Mapping(target = "id", source = "member.id")
    MemberOrderDto toMemberOrderDto(Member member, Order order);
}
